W1. System Modes and Memory

Author

Giancarlo Succi

Published

September 2, 2026

1. Theory

1.1 What Is an Operating System

An operating system (OS) is the layer of software between application programs and the bare hardware. It has two complementary jobs, and every exam question about “what the OS does” reduces to one of them.

Top-down, the OS is an extended machine. Real hardware is complicated and inconsistent: disks, network cards and printers all speak different low-level protocols. The OS hides this mess behind clean abstractions — files instead of disk blocks, sockets instead of wire packets, windows instead of video memory. A programmer reads and writes files; a disk driver inside the OS translates that into head movements and sector addresses.

Bottom-up, the OS is a resource manager. Many programs compete for the same CPU, memory and I/O devices, so the OS performs an orderly, controlled allocation of processors, memories and devices among them. Sharing (multiplexing) works in two ways. Time multiplexing lets programs take turns: the CPU executes one process for a few milliseconds, then another (printers work the same way — one job at a time). Space multiplexing splits the resource into parts used simultaneously: each program gets its own region of memory, each file its own disk blocks.

  • Key Pitfall: the two views answer different questions. “Why can I ignore the disk geometry?” — extended machine. “Why does my program slow down when ten others run?” — resource manager.
1.2 Kernel Mode and User Mode

Hardware would be defenceless if any program could execute any instruction: one buggy application could halt the machine or wipe a disk. Therefore most computers provide two execution modes. In kernel mode (supervisor mode) the OS runs with complete access to all hardware and may execute every instruction the machine supports. Everything else — browsers, mail readers, music players, the user interface itself — runs in user mode: only a subset of instructions is available, and anything affecting machine control or I/O is forbidden.

A user program that needs a service (read a file, send a packet) cannot perform it directly; it issues a system call (TRAP), which traps into the kernel, runs the OS routine with full privileges, and returns the result. Conceptually the machine is layered: hardware at the bottom, the OS in kernel mode above it, and user-mode programs on top.

  • Why it matters: isolation is what makes crashes survivable. A fault in a user-mode program kills only that program; the same fault in kernel mode halts the whole system (kernel panic / blue screen).
  • Key Pitfall: device drivers must live in the OS, precisely so they can run in kernel mode and touch controller registers — that is also why a bad driver can crash the machine.
1.3 History of Operating Systems

Each hardware generation forced a new kind of OS. Five dates and machines cover the whole story.

1st generation (1945–1955): vacuum tubes, plugboards. Colossus (Turing) and ENIAC (Mauchly): huge, slow, power-hungry, air-conditioned rooms, kilobytes of storage at best, programmed in machine language by rewiring. There was no OS at all — one program owned the whole machine.

2nd generation (1955–1965): transistors, batch systems. Transistors, core memory, magnetic tapes and disks; machines became smaller, cooler and cheaper. The first operating systems appeared to automate job sequencing on mainframes; programming moved to machine language and assembly.

3rd generation (1965–1980): integrated circuits. SSI/MSI chips, low power draw, high-level languages (Honeywell-6000, PDP, IBM-360/370). Three OS ideas born here still run the world: multiprogramming (several jobs in memory, CPU switches when one waits), spooling and timesharing. The second half (1971–1980) added microprocessors (LSI/VLSI): portable computers, RAID storage, data communication, fast large memories — and early uses in parallel processing, simulation, speech recognition and artificial intelligence.

4th generation (1980–1990): personal computers. LSI made a computer fit on a desk: the first microcomputer paired an Intel 8080 with an 8-inch floppy and ran CP/M (Control Program for Microcomputers), the first disk-based OS. IBM built the PC and contracted Bill Gates for its operating system.

5th generation (1990–present): mobile computers. From brick phones to touchscreen smartphones: the computer became a battery-powered, always-networked personal device.

  • How to remember: hardware shrinks and multiplies, software centralises control — no OS, batch OS, multiprogramming OS, personal OS, mobile OS.
1.4 Computer Hardware Review

An OS is tied to the hardware it runs on: it extends the instruction set and manages the resources. Five hardware areas matter.

1.4.1 Processors

Every CPU repeats one cycle: fetch the next instruction into a buffer, decode the opcode and operands, calculate effective operand addresses, fetch operands from memory (register operands skip this), execute, write the result back. To hold the working state the CPU has registers: general registers for variables and temporaries, the program counter (address of the next instruction), the stack pointer (top of the in-memory stack), and the PSW (Program Status Word: comparison flags, CPU priority, kernel/user mode bit and other control bits).

Raw speed comes from overlap. A three-stage pipeline (fetch → decode → execute units working on three instructions at once) and superscalar designs (parallel pipelines feeding parallel execute units through a holding buffer) do more per clock. Multithreading (hyper-threading) goes further: the CPU keeps the state of two threads and switches between them in nanoseconds, so when one thread stalls on a memory read the other runs — note this hides latency but is not true parallelism. True parallelism needs several cores: modern chips are multicore (a quad-core with a shared L2 cache versus separate L2 per core are the two textbook layouts), and a GPU is thousands of tiny cores for small parallel computations such as polygon rendering. Multicore hardware requires a multiprocessor OS.

1.4.2 Memory

Memory is a hierarchy: each higher layer is faster, smaller and more expensive per bit. The lecture’s reference numbers are worth memorising: registers (~1 nsec, under 1 KB), cache (~2 nsec, ~4 MB), main memory (~10 nsec, 1–8 GB), magnetic disk (~10 msec, 1–4 TB).

Main memory is divided into cache lines of typically 64 bytes; the hottest lines live in a cache inside the CPU. On a read, hardware checks the cache first: a hit costs about 2 clock cycles and no bus traffic, a miss goes to main memory. Machines often stack two or three cache levels, each slower and bigger. Cache design is four questions: when to insert, where to place, what to evict, and where the evicted item goes.

Technologies differ in volatility. RAM serves whatever the cache cannot; ROM keeps factory-programmed contents without power (classically the bootstrap loader lives there); EEPROM and flash are also nonvolatile but erasable and rewritable — flash sits between RAM and disk in speed, backs phones and USB sticks, and wears out with writes. CMOS memory holds the clock, date and boot configuration such as which disk to boot from.

  • Worked micro-example (average access time): with cache hit rate at cycles, RAM hit rate at cycles on a miss, disk cycles otherwise: The lesson: even a 2% trip to disk dominates everything — hierarchy performance is decided by miss rates, not by cache speed.
1.4.3 Disks

A hard disk is a stack of platters; each surface is divided into concentric tracks, each track into sectors (an arc of a track is a segment). An actuator arm swings the read/write heads over the surfaces. Every access pays three costs: seek time (moving the head), rotation delay / latency (waiting for the sector to spin under the head) and transfer time (the actual bit flow, i.e. data rate).

1.4.4 I/O Devices

Each device has two halves: a controller (electronics accepting OS commands) and the device itself (deliberately simple, standardised interface). The program that talks to the controller is the device driver; it must live in the OS to run in kernel mode. Controllers expose a few registers; the set of all of them is the I/O port space. Two addressing schemes exist: memory-mapped I/O (registers appear at ordinary memory addresses) and a separate port space with special IN/OUT instructions usable only in kernel mode.

Getting data in and out has three generations. Busy waiting (polling): the driver starts the transfer and spins in a loop asking “done yet?” — simple, but the CPU is tied up. Interrupts: the driver starts the device, blocks the caller and does other work; on completion the controller raises an interrupt, the CPU vectors through the interrupt vector (a table mapping device numbers to handler addresses) into the handler, then returns to the user program. DMA (Direct Memory Access): a dedicated chip moves whole blocks between memory and controller with no CPU involvement; the CPU only programs the transfer and receives one interrupt at the end.

  • Key Pitfall: interrupts do not make I/O faster — they free the CPU while I/O is in flight. DMA then removes even the per-byte CPU cost.
1.4.5 Buses

Components meet at buses, and the OS must know every one for configuration. A shared bus (one set of wires, many devices) needs an arbiter deciding who transmits. A parallel bus spreads one word over many wires (classic PCI: 32 bits over 32 wires); a serial bus sends bits down one lane, scaling by adding lanes. Concrete buses: DDR3/DDR4 (CPU–RAM), PCIe (graphics), DMI (bridge-to-bridge hub link), SCSI/SATA (disks), USB (centralised: the root device polls every peripheral for traffic). Before Plug & Play, each card hard-coded its interrupt line and register addresses, so two cards could collide; Plug & Play enumerates devices and centrally assigns interrupts and addresses.

1.5 Booting the Computer

Starting the machine is a relay race, in strict order. BIOS, a program on the motherboard with low-level I/O routines, runs first and performs POST (Power-On Self-Test): memory size, device presence, basic integrity. It then scans the buses to enumerate devices and picks the boot device from the list stored in CMOS memory. The first sector of that device — the boot sector — is loaded and executed; it reads the partition table at the sector’s end to find the active partition. A secondary boot loader from that partition loads the OS itself. The newborn OS queries the BIOS for the hardware inventory, checks it has a driver per device, loads the drivers into the kernel, initialises its tables, spawns background processes, and finally starts a login prompt or GUI.

  • Why the order matters: each stage only knows how to load something slightly smarter than itself — ROM code cannot parse filesystems, so booting climbs BIOS → boot sector → loader → OS.
1.6 The OS Zoo

Different machines need different operating systems. Mainframe OSs (OS/360, OS/390) live in data centres and are tuned for hundreds of concurrent I/O-heavy jobs. Server OSs (UNIX, Linux, Windows Server, FreeBSD, Solaris) serve many users over a network, sharing hardware and software. Multiprocessor OSs coordinate several CPUs — today every PC and notebook OS qualifies (Linux, Windows). Personal computer OSs need a single-user interactive system (Windows, macOS, Linux, FreeBSD). Handheld OSs target phones and tablets (Android, iOS). Embedded OSs hide inside devices that take no installed software — microwaves, MP3 players, TVs, cars (Embedded Linux, QNX, VxWorks). Sensor-node OSs (TinyOS) run on motes that are complete tiny computers — CPU, RAM, ROM plus environmental sensors, meshed over wireless to a base station. Real-time OSs keep deadlines: hard real-time guarantees the action happens in time, always; soft real-time tolerates an occasional miss without damage (QNX). Smart-card OSs are the smallest of all: a CPU on a credit card, often holding a JVM interpreter so downloaded applets run on the card.


2. Definitions

  • Operating System: A system software that manages computer hardware resources and provides common services for computer programs.
  • Resource Management: The primary function of an operating system to efficiently allocate hardware components like CPU, memory, and I/O devices among multiple programs.
  • Abstraction: A mechanism provided by the operating system to hide complex bare-metal hardware details behind clean, simple interfaces.
  • Multiprogramming: The allocation and execution of multiple programs on a single computer system simultaneously.
  • Time-sharing: A logical extension of multiprogramming where computing resources are shared among several users concurrently through rapid context switching.
  • Kernel Mode: A privileged execution mode in which code has complete and unrestricted access to all underlying hardware and memory addresses.
  • User Mode: A restricted execution mode where applications cannot directly access hardware or reference memory, requiring system APIs to perform privileged operations.
  • Hyperthreading: A technology that allows a single physical CPU core to execute multiple threads concurrently by providing duplicate logical processors.
  • Virtual Memory: A memory management capability that uses disk storage to extend apparent physical RAM capacity.

3. Practice

3.1. OS Functions (Tutorial 1, Problem 1.1)

What are the two main functions of an operating system?

Click to see the solution

The two main functions are: 1. Resource management: Efficiently allocating CPU, memory, storage, and I/O devices among competing processes and users. 2. Providing fine abstractions from the bare metal: Presenting clean, uniform, and high-level virtual interfaces (such as files, processes, and sockets) to hide the complex and heterogeneous underlying hardware details.

Answer: Resource management and hardware abstraction.

3.2. Time-Sharing vs Multiprogramming (Tutorial 1, Problem 1.3)

What is the difference between time-sharing and multiprogramming systems?

Click to see the solution
  • Multiprogramming is the basic allocation and concurrent retention of multiple programs in main memory simultaneously, allowing the CPU to switch to another program when one is waiting for I/O, thereby maximizing CPU utilization.
  • Time-sharing (or multitasking) is a logical extension of multiprogramming where CPU resources are rapidly shared among several interactive users or processes using timer interrupts, giving each user the illusion of dedicated access to the machine.
  • Relationship: All time-sharing systems are multiprogramming systems, but not all multiprogramming systems are time-sharing systems (some early multiprogramming systems ran batch jobs without interactive user turnaround).

Answer: Time-sharing extends multiprogramming with rapid CPU sharing; every time-sharing system is multiprogramming, not vice versa.

3.3. Kernel Mode and User Mode (Tutorial 1, Problem 1.10)

What is the difference between kernel mode and user mode, and how does this dual-mode design aid operating system construction?

Click to see the solution
  • Kernel Mode: Executing code has complete, unrestricted access to the underlying hardware. It can execute any privileged CPU instruction and reference any physical or virtual memory address. Crashes in kernel mode are catastrophic and halt the entire operating system (kernel panic / BSOD).
  • User Mode: Executing code operates under hardware-enforced restrictions. It cannot directly access hardware devices or reference arbitrary memory locations. Applications must invoke system calls (APIs) to request kernel services on their behalf.
  • Design Aid: This isolation protects system stability and security. Because user-mode applications cannot directly corrupt critical hardware state or other users’ memory spaces, bugs and crashes in user mode are completely isolated and fully recoverable.

Answer: Kernel mode runs unrestricted, user mode is restricted to syscalls — faults stay isolated.

3.4. Hardware Video RAM and Cost Calculations (Tutorial 1, Problem 1.8)

Calculate memory requirements and historical vs. modern costs for display buffers:

Click to see the solution
  • Monochrome text screen ():
    • Buffer size: ().
    • Cost at 1980 prices (): .
  • -pixel 24-bit color bitmap:
    • Total bits: .
    • Total bytes: ( or ).
    • Cost at 1980 prices (): .
    • Modern cost: Negligible (fractions of a cent, given modern RAM costs of roughly per megabyte).

Answer: 2000 B (≈$10 in 1980) vs 3.09 MiB (≈$15,820 in 1980, negligible today).

3.5. CPU Scheduling and Hyperthreading Execution Time (Tutorial 1, Problem 1.13)

Consider a system with 2 physical CPUs, each with 2 threads (4 logical processors total). Three 100% CPU-bound programs (, , ) start simultaneously without blocking or migrating. How long will execution take under various scheduling choices?

Click to see the solution
  • Case 1: and on CPU A, on CPU B
    • CPU A runs (5 ms) and (10 ms). Since they run simultaneously on separate logical threads of the same physical core, they share execution units. finishes at 5 ms, leaving to run alone until 10 ms. Total time on CPU A = 10 ms.
    • CPU B runs (20 ms) alone. Total time on CPU B = 20 ms.
    • Total completion time: .
  • Case 2: and on CPU A, on CPU B
    • CPU A runs (5 ms) and (20 ms). Time taken = 20 ms.
    • CPU B runs (10 ms). Time taken = 10 ms.
    • Total completion time: .
  • Case 3: and on CPU A, on CPU B
    • CPU A runs (10 ms) and (20 ms). Time taken = 20 ms.
    • CPU B runs (5 ms). Time taken = 5 ms.
    • Total completion time: (assuming concurrent hyperthreaded execution; if resource contention serializes them fully on the core, it takes up to ).
  • Case 4: All three programs scheduled on CPU A
    • CPU A runs all threads, while CPU B sits idle. The worst-case sequential execution of all programs on a single core/hyperthreaded package takes up to .

Answer: 20 ms for balanced placements, up to 35 ms with everything on one CPU.

3.6. Hierarchical Memory Access Time (Tutorial 1, Problem 1.15)

A computer system has cache memory, main memory (RAM), and disk storage with the following access times:

  • Cache access:
  • RAM access:
  • Disk access:

Given a cache hit rate of () and a main memory hit rate (after a cache miss) of (), calculate the average memory access time.

Click to see the solution

Using the provided probabilities:

  • Cache hit contribution:
  • RAM hit (cache miss) contribution:
  • Disk hit (cache & RAM miss) contribution:

Summing the components:

Answer: ns s, dominated by the disk-miss term.